package com.zigong.app.ui.adapter.holder;

import android.content.Context;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.jiongbull.jlog.JLog;
import com.ruihang.generalibrary.utils.ListUtils;
import com.zigong.app.R;
import com.zigong.app.beans.FProgramme;
import com.zigong.app.ui.adapter.AnchorHomePageAdapter;
import com.zigong.app.ui.adapter.AnchorRecomAdapter;
import com.zigong.app.ui.util.IListShowData;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/7/13 0013.
 */

public class AnchorRecommenHolder extends BaseAnchorHolder<FProgramme> {
    private List<FProgramme> recomList = null;
    private GridLayoutManager manager;
    @BindView(R.id.item_anchor_recommen_list)
    protected RecyclerView recommenList;
    private AnchorRecomAdapter adapter;
    private int size = 0;

    public AnchorRecommenHolder(Context context, View itemView, List<IListShowData> list) {
        super(context, itemView);
        recomList = new ArrayList<>();
        if (ListUtils.isListValued(recomList)) {
            recomList.clear();
        }
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getDataViewType() == AnchorHomePageAdapter.VIEWTYPE_RECOMMEND) {
                size = i;
                recomList.add((FProgramme) list.get(i));
            }
        }
    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(FProgramme fProgramme) {
        if (size == getAdapterPosition()) {
            JLog.e("====relist=="+recomList.size());
            manager = new GridLayoutManager(context, 2);
            recommenList.setItemAnimator(new DefaultItemAnimator());
            recommenList.setLayoutManager(manager);
            if (adapter == null) {
                adapter = new AnchorRecomAdapter(context, recomList);
                recommenList.setAdapter(adapter);
            } else {
                adapter.setData(recomList);
            }

        }

    }
}
